package eproject.mm.com.projectsupervision.fragment;

import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import eproject.mm.com.projectsupervision.R;

public abstract class LazyFragment extends Fragment {
    protected boolean isUIVisible = false;
    private boolean isViewCreated = false;

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        isViewCreated = true;
        onVisible();
    }

    @Override  
    public void setUserVisibleHint(boolean isVisibleToUser) {  
        super.setUserVisibleHint(isVisibleToUser);  

        if(isVisibleToUser){
            isUIVisible = true;
            onVisible();
        }else{
            isUIVisible = false;
        }  
    }  
  
    private void onInVisible() {  

    }  
  
    private void onVisible() {
        if(isUIVisible && isViewCreated) {
            LazyLoad();
            isViewCreated = false;
            isUIVisible = false;
        }
    }

    public abstract void LazyLoad();  
}  